<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2008 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: register.php
| Author: Nick Jones (Digitanium)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "maincore.php";
require_once THEMES."templates/header.php";
include LOCALE.LOCALESET."register.php";
include LOCALE.LOCALESET."user_fields.php";


//Henter avloser id fra URL for å hente riktig kontrakter fra DB
$avloserid=$_GET['avloserid'];
//---------------------------------------------------------------------------------------------------------------------+
//------Funksjon for bekreftelse og sletting av kontrakt mot DB   (Hoppes over hvis ikke slettknappen er trykket)------+
//---------------------------------------------------------------------------------------------------------------------+
if(isset($_GET['slett'])) 

if(isset($_GET['confirm'])) {
	$sid=$_GET['sid'];
	$confirm=$_GET['confirm'];
	if ($_GET['confirm'] == "ja" )
		{
		$query1="DELETE 
				 FROM avlosermote 
				 WHERE moteid=$sid";
		mysql_query($query1);
		header("Refresh: 1; url=avlosermote.php?avloserid=".$_GET['avloserid']."&sjekk=nei");
		}
}
//---------------------------------------------------------------------------------------------------------------------+
//------------------------------------Slutt-på-funksjon-for-sletting-av-kontrakt---------------------------------------+
//---------------------------------------------------------------------------------------------------------------------+


//---------------------------------------------------------------------------------------------------------------------+
//----------Funksjon for lagring av kontrakt til DB     (Hoppes over hvis ikke lagreknappen er trykket)----------------+
//---------------------------------------------------------------------------------------------------------------------+
//Henter sjekk fra URL
$sjekk=$_GET['sjekk'];
if($sjekk=="ja") {
	$theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
	$info= $_POST["ud_info"];	
	$time = strtotime( $theDate );
	$dagsdato = date('Y-m-d');
	$dagstime = strtotime( $dagsdato );
		if($time < $dagstime){
		echo" <h1 align='center'>Velg en senere dato!</h1>";	
		}else{
				$db = mysql_connect($GLOBALS['db_host'], $GLOBALS['db_user'], $GLOBALS['db_password']);
				mysql_select_db($GLOBALS['db_name'], $db);  
				$query1="INSERT INTO avlosermote VALUES ('','$theDate','$info', $avloserid)";
				mysql_query($query1);
				
		}
	
	}
//---------------------------------------------------------------------------------------------------------------------+
//------------------------------------Slutt-på-funksjon-for-lagring-av-kontrakt----------------------------------------+
//---------------------------------------------------------------------------------------------------------------------+


//---------------------------------------------------------------------------------------------------------------------+
//----------Kode for uthenting av kontraktdata fra DB og HTML printing til nettleser----(Utføres ved sidelasting)------+
//---------------------------------------------------------------------------------------------------------------------+

$query="SELECT  moteid, dato, avlosermote.avloserid, info
		FROM avlosermote, avloser
		WHERE avlosermote.avloserid = avloser.avloserid
		AND avlosermote.avloserid = $avloserid
		ORDER BY avlosermote.dato DESC;";
$result=mysql_query($query);
$num=mysql_numrows($result);
//------------
echo "
	<br></br>
	<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='profil.php?avloserid=$avloserid'><b><---  Tilbake til profil</b></a></p>
	<table class='capmain' border='0' cellpadding='0' align='center'>
		<tr>
			<th>Medarbeidersamtaler</th>
		</tr>
	</table>
	<table class='imagetable' border='0' cellpadding='5' align='center'>
		<tr>
			<th><b>Dato</b></th>
			<th><b>Info</b></th>
			
			
			<th><b></b></th>
		</tr>
";

$i=0;
while ($i < $num) {
	$dato=mysql_result($result,$i,"dato");
	$info=mysql_result($result,$i,"info");	
	$nydato = date('d-M-Y', strtotime($dato));
	$sid=mysql_result($result,$i,"moteid");
	$time = strtotime( $dato );
	$dagsdato = date('Y-m-d');
	$dagstime = strtotime( $dagsdato );
	$differanse = $time - $dagstime;
	$utlop = round($differanse / 86400);
	
	if($utlop <= 31 && $utlop >=0)
	{
	$varsel='red'; 
	$varsel2='a';
	$varsel3='b';
	}else{
	$varsel='';
	$varsel2='';
	$varsel3='';
	}
	++$i;
	echo "
		<form action='avlosermote.php?confirm=ja&sid=".$sid."&avloserid=".$avloserid."&slett=ja&sjekk=nei' onSubmit='return validateUpdate()' method='post'>
		<tr class='$varsel'>
			<td class='$varsel3'>$nydato</td>
			<td class='$varsel3'>$info</td>
			<td class='$varsel3' align=center><input type='submit' value='Slett' /></td>			
		</tr></form>
		";
} //Slutt på While-løkke

echo "	
		</table>		
		<form action='avlosermote.php?avloserid=".$avloserid."&sjekk=ja' method='post'>";
		require_once('calendar/classes/tc_calendar.php');
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("calendar/images/iconCalendar.gif");
		$myCalendar->setDate(01, 01, 2011);
		$myCalendar->setPath("calendar/");
		$myCalendar->setYearInterval(2010, 2050);
		$myCalendar->dateAllow('2010-01-01', '2050-03-01');
		
		echo" 	
			<table class='imagetable' border='1' cellpadding='0' align='center' >
				<tr>
					<th width='40%'>M&oslash;testart:</th><th width='40%'>Info:</th><th width='20%'></th></tr>
					
				<tr>
					<td width='40%'>";	$myCalendar->writeScript(); echo"  </td>		
					<td width='40%'><input type='text' name='ud_info' value='Info'>  </td>
					<td width='20%'><input type='Submit' value='Legg til'></td>
				</tr>
					
					
					
				
				</form>
			</table><br></br>
";

//---------------------------------------------------------------------------------------------------------------------+
//----------Slutt på kode for uthenting av kontraktdata fra DB og HTML printing til nettleser--------------------------+
//---------------------------------------------------------------------------------------------------------------------+
require_once THEMES."templates/footer.php";
?>

<!-- JavaScript and HTML codes by Quackit.com -->
<script language="javascript" type="text/javascript" >
function validateUpdate(){
		var confirmLeave = confirm('Er du sikker?');
		return confirmLeave;
}
</script>
